package com.z.service.impl;

import com.z.dao.UsersDao;
import com.z.dao.impl.UsersDaoImpl;
import com.z.pojo.Goods;
import com.z.pojo.PageBean;
import com.z.pojo.Users;
import com.z.service.UsersService;

import java.sql.SQLException;
import java.util.List;

/**
 * @author 张福兴
 * date 2021/9/7
 */
public class UsersServiceImpl implements UsersService {
    private final UsersDao usersDao = new UsersDaoImpl();

    @Override
    public Users loginCheck(String account, String password) {
        Users users = null;
        try {
            users = usersDao.selectOneUsers(account, password, 0);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return users;
    }

    @Override
    public PageBean<Users> manageUsers(Integer nowpage, Integer eachcount, String term) {
        List<Users> list = null;
        Integer count = 0;
        try {
            list = usersDao.selectPageUsers(nowpage, eachcount, term);
            count = usersDao.count(term);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        PageBean<Users> pageBean = new PageBean<>();

        pageBean.setNowpage(nowpage);
        pageBean.setEachcount(eachcount);
        pageBean.setLists(list);
        pageBean.setTotalcount(count);
        return pageBean;
    }

    @Override
    public Integer updatebyuid(Integer uid,Integer level) {
        Integer updatebyuid=0;
        try {
            updatebyuid = usersDao.updatebyuid(uid, level);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return updatebyuid;
    }

    @Override
    public Users selectByuid(Integer uid) {
        Users users=null;
        try {
            users = usersDao.selectUsersByuid(uid);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return users;
    }

    @Override
    public Integer updateUsersByuid(Users users) {
        Integer integer = 0;
        try {
            integer = usersDao.updateUsersByuid(users);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return integer;
    }

    @Override
    public Integer addUsers(Users users) {
        Integer integer = 0;
        try {
            integer=usersDao.insertUsers(users);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return integer;
    }

    @Override
    public Users usersLogin(String account, String password) {
        Users users = null;
        try {
            users = usersDao.selectOneUsers(account, password, 1);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return users;
    }
}
